import Api from '../api'
const state = {
	dict: {}
}

const mutations = {
	SET_DICT: (state, dict) => {
		state.dict = dict
	}
}

const actions = {
	// 获取字典数据
	getDict({ commit }) {
		return new Promise((resolve, reject) => {
			Api.getDict().then(res => {
				const obj = {}
				res.forEach(el => {
					obj[el.code] = el
				})
				commit('SET_DICT', obj)
				resolve()
			})
		})
	}
}
const getters = {
	getDictData: state => {
		return state.dict
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions,
	getters
}
